unit ReceteUretimEmriOzelTanim;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, XPMan, StdActns, ActnList, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxDBLookupComboBox, cxButtonEdit, cxImageComboBox, cxCheckBox,
  cxDropDownEdit, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, ADODB,
  cxSpinEdit, ComCtrls;

type
  TfmReceteUretimEmriOzelTanim = class(TfmFormClass)
    aqEntry: TADOQuery;                          
    dsEntry: TDataSource;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1DBTableView1Tur: TcxGridDBColumn;
    cxGrid1DBTableView1AnaUrunKodu: TcxGridDBColumn;
    cxGrid1DBTableView1OlanUrunCikisi: TcxGridDBColumn;
    cxGrid1DBTableView1OlanStokkodu: TcxGridDBColumn;
    cxGrid1DBTableView1OlanUstGrupId: TcxGridDBColumn;
    cxGrid1DBTableView1OlanGrupId: TcxGridDBColumn;
    cxGrid1DBTableView1OlacakUrunCikisi: TcxGridDBColumn;
    cxGrid1DBTableView1OlacakStokkodu: TcxGridDBColumn;
    cxGrid1DBTableView1Oran: TcxGridDBColumn;
    cxGrid1DBTableView1CikacakUrunCikisi: TcxGridDBColumn;
    cxGrid1DBTableView1CikacakStokkodu: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure cxGrid1DBTableView1AnaUrunKoduPropertiesValidate(
      Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
      var Error: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmReceteUretimEmriOzelTanim: TfmReceteUretimEmriOzelTanim;

implementation
uses data, UnitGenel;
{$R *.dfm}

procedure TfmReceteUretimEmriOzelTanim.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmReceteUretimEmriOzelTanim := nil;
end;

procedure TfmReceteUretimEmriOzelTanim.FormShow(Sender: TObject);
begin
  inherited;
  OpenQueryOnDataSet(aqEntry.SQL.Text, aqEntry);
end;

procedure TfmReceteUretimEmriOzelTanim.cxGrid1DBTableView1AnaUrunKoduPropertiesValidate(
  Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption;
  var Error: Boolean);
var
  Bilgi: string;
  StokKod: integer;
  Stokkodu: string[25];
  StokFisiTipi: char;
begin
//  ShowMessage(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName);
//  ShowMessage(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.Name);
//  ShowMessage(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedColumn.Name);

  TcxButtonEdit(sender).Tag := 1;
  Bilgi := StokBul(Sender, 0, StokFisiTipi);

  if Bilgi = '' then
    exit;

  if Bilgi <> '0' then
  begin
    Stokkod := Strtoint(Copy(Bilgi, 1, Pos(',', Bilgi) - 1));
    Delete(Bilgi, 1, Pos(',', Bilgi));
    Stokkodu := Copy(Bilgi, 1, Pos(',', Bilgi) - 1);

    if not (aqEntry.State in [dsInsert, dsEdit]) then
      aqEntry.Edit;

    aqEntry.FieldByName(Copy(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName, 1, Length(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName) - 1)).Value := Stokkod;
    aqEntry.FieldByName(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName).Value := Stokkodu;
  end
  else
  begin
    aqEntry.FieldByName(Copy(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName, 1, Length(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName) - 1)).Value := Null;
    aqEntry.FieldByName(TcxGridDBTableView(TcxButtonEdit(Sender).Owner).Controller.FocusedItem.DataBinding.FilterFieldName).Value := '';
  end;
end;

end.

